parameters:
  nameSuffix: ''
  buildConfig: ''
  hostedOs: ''
  osGroup: ''
  publishArtifactsForWorkload: always()
  publishWBT: always()

steps:

  - task: CopyFiles@2
    displayName: Copy artifacts needed for running WBT
    condition: and(succeeded(), ${{ parameters.publishArtifactsForWorkload }})
    inputs:
      SourceFolder: '$(Build.SourcesDirectory)/artifacts'
      Contents: |
        packages/$(_BuildConfig)/Shipping/**
        packages/$(_BuildConfig)/NonShipping/**
        bin/WasmAppBuilder/**/*
        bin/WasmBuildTasks/**
        bin/WorkloadBuildTasks/**
        bin/installer.tasks/**
        bin/Crossgen2Tasks/**
      TargetFolder: '$(Build.StagingDirectory)/IntermediateArtifacts'
      CleanTargetFolder: true

  - task: PublishBuildArtifacts@1
    displayName: Publish intermediate artifacts
    condition: and(succeeded(), ${{ parameters.publishArtifactsForWorkload }})
    inputs:
      pathToPublish: '$(Build.StagingDirectory)/IntermediateArtifacts'
      artifactName: BuildArtifacts_${{ parameters.osGroup }}_wasm_$(_hostedOs)_${{ parameters.buildConfig }}_${{ parameters.nameSuffix }}
      artifactType: container

  - task: CopyFiles@2
    displayName: Copy WBT
    condition: and(succeeded(), ${{ parameters.publishWBT }})
    inputs:
      SourceFolder: '$(Build.SourcesDirectory)/artifacts'
      Contents: helix/buildwasmapps/**
      TargetFolder: '$(Build.StagingDirectory)/IntermediateArtifacts'
      CleanTargetFolder: true

  - task: PublishBuildArtifacts@1
    displayName: Publish Wasm.Build.Tests archive
    condition: and(succeeded(), ${{ parameters.publishWBT }})
    inputs:
      pathToPublish: '$(Build.StagingDirectory)/IntermediateArtifacts'
      artifactName: WasmBuildTests_$(_hostedOs)_${{ parameters.nameSuffix }}
      artifactType: container
